package Model;
import java.util.HashMap;
import java.util.UUID;

import Controller.Ride;
import Controller.RideInfo;


public class KidImpl implements Kid {

	private final int id;
	private final String name;
	private final int age;
	private final int height;
	private RideInfo currentRide;
	private int regularTickets;
	private HashMap<RideInfo, Integer> extremeTickets;
	private Escort escort;
	
	private int generateID() { return this.hashCode(); } 
	
	private KidImpl(String name, int age, int height, Escort escort) {
		this.name = name;
		this.age = age;
		this.height = height;
		id = generateID();
		currentRide = null;
		regularTickets = 0;
		extremeTickets = new HashMap<RideInfo, Integer>();
		this.escort = escort;
	}
	
	@Override
	public boolean equals(Object other) {
		if(other instanceof Kid)
			return ((Kid)other).getID() == id;
		return false;
	}
	
	//exceptions?
	public static KidImpl newInstance(String name, int age, int height, Escort escort) {
		if(name.isEmpty())
			return null;
		if(age < MIN_AGE || age > MAX_AGE)
			return null;
		if(height < MIN_HEIGHT || height > MAX_HEIGHT)
			return null;
		if(escort == null)
			return null;
		return new KidImpl(name, age, height, escort);
	}
	
	@Override
	public int getID() { return id; }
	@Override
	public String getName() { return name; }
	@Override
	public int getAge() { return age; }
	@Override
	public int getHeight() { return height; }
	
	@Override
	public boolean getOnRide(RideInfo rideInfo) {
		/*if(rideInfo.type == Ride.Type.REGULAR && regularTickets > 0) {
			regularTickets--; //remove a ticket
			escort.charge(rideInfo.getPrice()); //charge the escort
			currentRide = rideInfo;
			return true;
		} else if(rideInfo.type == Ride.Type.EXTREME && extremeTickets.containsKey(rideInfo)) {
			extremeTickets.put(rideInfo, extremeTickets.get(rideInfo) - 1); //remove a ticket
			escort.charge(rideInfo.price); //charge the escort
			currentRide = rideInfo;
			return true;
		}*/
		return false;
	}

	@Override
	public void getOffRide() {
		//not on ride = throw exception?
		currentRide = null;
	}

	@Override
	public boolean updateTickets(RideInfo rideInfo, int amount) {
		/*if(rideInfo.type == Ride.Type.REGULAR)
			regularTickets += regularTickets + amount >= 0 ? amount : -regularTickets;
		else if(rideInfo.type == Ride.Type.EXTREME) {
			Integer num = new Integer(extremeTickets.get(rideInfo));
			extremeTickets.put(rideInfo, (num + amount > 0) ? num + amount : 0);
		}*/
		return false;
	}

	@Override
	public Kid setName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Kid setAge(int age) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Kid setHeight(int height) {
		// TODO Auto-generated method stub
		return null;
	}

}
